<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 8/5/14
 * Time: 1:29 PM
 */

namespace UploadFile\Factory;
use UploadFile\Mapper;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class UploadFileLinkerMapperFactory implements FactoryInterface
{
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /* @var $options Options\ModuleOptions */
        $options = $serviceLocator->get('upload_file_module_options');
        /* @var $dbAdapter Db\Adapter\Adapter */
        $dbAdapter = $serviceLocator->get('user_zend_db_adapter');

        $mapper = new Mapper\UploadFileLinkerMapper();
        $mapper->setDbAdapter($dbAdapter);

        $entityClass = $options->getUploadFileLinkerEntityClass();

        /* @var $hydrator Hydrator\HydratorInterface */
        $hydrator = $serviceLocator->get('upload_file_linker_hydrator');

        $mapper
            ->setEntityPrototype(new $entityClass)
            ->setHydrator($hydrator)
            ->setTableName($options->getTableUploadFileLinkerName())
        ;
        return $mapper;
    }
} 